let stars = document.querySelectorAll('.star')
stars.forEach(item => {
    item.onmouseover = function() {
        let fiveStar = this.parentNode.querySelectorAll('.star>img')
        fiveStar.forEach(function(star, index) {
            star.addEventListener('click', function() {
                // 清除之前所有的选中状态  
                fiveStar.forEach(s => s.classList.remove('selected'));

                // 设置当前及之前的星星为选中状态  
                for (let i = 0; i <= index; i++) {
                    fiveStar[i].classList.add('selected');
                }

            });
        });
    }
})